package TDALista;

import java.util.Iterator;
import java.util.NoSuchElementException;

import Excepciones.BoundaryViolationException;
import Excepciones.InvalidPositionException;

public class ElementIterator <E> implements Iterator<E> {

	protected PositionList<E> list;
	protected Position<E> cursor;

	public ElementIterator (PositionList<E> L){
		list = L;
		cursor = (list.isEmpty())? null : list.first();
	}
	public boolean hasNext(){
		return (cursor!= null);
	}
	public E next() throws NoSuchElementException {
		if (cursor == null)
			throw new NoSuchElementException("No existe elemento siguiente");
		
		E toReturn = cursor.element();
		try {
			cursor = (cursor == list.last())? null : list.next(cursor);
		} catch (InvalidPositionException e) {e.printStackTrace();}
		catch (BoundaryViolationException e) {e.printStackTrace();}
		return toReturn;
	}
	@Override
	public void remove() {
		// TODO Auto-generated method stub
		
	}
}

